﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Course.Models;
using Course.Views;

namespace Course.Controllers
{
  public   class RegisterController
    {
        public DataClasseDataContext context = new DataClasseDataContext();
        public Register View;
        public RegisterModel Model;
         public RegisterController(Register view) {
            Model = new RegisterModel();
            this.View = view;
            this.View.Controller = this;
        }
         public String register()
         {
             User user = context.User.SingleOrDefault(u=>u.UserId==Model.userId);
             if (user != null) return "您的学号或者教职工号已经被注册过了！";
             else
             {
                 if (Model.password.CompareTo(Model.confirm)!= 0) return "密码和确认密码不一致！";
                 else
                 {
                     User u = new User();
                     u.UserId = Model.userId;
                     u.UserName = Model.userName;
                     u.Password = Model.password;
                     u.Grade = Model.grade;
                     u.Class = Model.myClass;
                     u.Role = Model.eRole;
                     context.User.InsertOnSubmit(u);
                     context.SubmitChanges();
                     return "success";
                 }
             }
         }
    }
}
